package com.zqq.user.presenter

import com.zhuanju.core.utils.ZLog
import com.zqq.baselibrary.ext.excute
import com.zqq.baselibrary.http.rx.BaseSubscriber
import com.zqq.baselibrary.presenter.BasePresenter
import com.zqq.user.presenter.view.ResetPwdView
import com.zqq.user.service.UserService
import javax.inject.Inject
import javax.inject.Named

/**
 * 重置密码Presenter
 * wc
 * @author zqq on 2019/5/25.
 */
class ResetPwdPresenter @Inject constructor() : BasePresenter<ResetPwdView>() {

    @Inject
    @field:[Named("service")]
    lateinit var userService: UserService

    //重置密码
    fun resetPwd(mobile: String, pwd: String) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        userService.resetPwd(mobile, pwd)
                .excute(object : BaseSubscriber<Boolean>(mView) {
                    override fun onNext(t: Boolean) {
                        if (t)
                            mView.onResetPwdResult("重置密码成功")
                    }

                    override fun onError(e: Throwable) {
                        super.onError(e)
                        mView.onResetPwdResult("重置密码测试")
                    }

                    override fun onCompleted() {
                        super.onCompleted()
                        ZLog.e("重置密码")
                    }
                }, lifecycleProvider)
    }

}